import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

public class Client {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String userId = "1001";
		javax.ws.rs.client.Client client = ClientBuilder.newClient();
		WebTarget target = client
				.target("http://localhost:9030/services/userService/getName.json");
		Response response = target.request().post(
				Entity.entity(userId, MediaType.APPLICATION_JSON_TYPE));

		try {
			if (response.getStatus() != 200) {
				throw new RuntimeException("Failed with HTTP error code : "
						+ response.getStatus());
			}
			System.out.println("--反馈结果:"
					+ response.readEntity(String.class));
		} finally {
			response.close();
			client.close(); // 在真正开发中不要每次关闭client，比如HTTP长连接是由client持有的
		}

	}

}
